package com.tech.repository.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;

/**
 * 商品(旧书)实体类
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Goods implements Serializable {
	/**
	 * 商品编号
	 */
	private Integer gid;
	/**
	 * 商品名
	 */
	private String gname;
	/**
	 * 商品人气
	 */
	private int gpopularity;
	/**
	 * 商品简介
	 */
	private String gintroduce;
	/**
	 * 商品原价
	 */
	private double gprice;
	/**
	 * 商品二手价
	 */
	private double gsecprice;
	/**
	 * 商品卖家卖家ID
	 */
	private Integer uid;
	/**
	 * 商品新旧程度
	 */
	private Condition gcondition;
	private SendMode gsendmode;
	/**
	 * 卖家姓名
	 */
	private String uname;
	/**
	 * 商品数量，因为是旧书，所以大部分情况应该都为 1
	 */
	private int gcount;
	private Date gcreatetime;

	public Goods(Integer gid) {
		this.gid = gid;
	}

	/**
	 * 所有配送方式的集合
	 */
	public enum SendMode {
		/**
		 * 送货上门
		 */
		DELIVERY,
		/**
		 * 上门自取
		 */
		HELP_YOURSELF;

		public static SendMode parse(String str) {
			SendMode result = null;
			switch (str) {
				case "送货上门" -> result = DELIVERY;
				case "上门自取" -> result = HELP_YOURSELF;
			}
			return result;
		}

		public static SendMode[] toArray() {
			return new SendMode[]{DELIVERY, HELP_YOURSELF};
		}

		@Override
		public String toString() {
			String result = null;
			switch (this) {
				case DELIVERY -> result = "送货上门";
				case HELP_YOURSELF -> result = "上门自取";
			}
			return result;
		}
	}

	public enum Condition {
		NEW, ALMOST_NEW, SLIGHT_TRACE, OBVIOUS_TRACE;

		public static Condition parse(String str) {
			Condition result = null;
			switch (str) {
				case "全新" -> result = NEW;
				case "几乎全新" -> result = ALMOST_NEW;
				case "轻微使用痕迹" -> result = SLIGHT_TRACE;
				case "明显使用痕迹" -> result = OBVIOUS_TRACE;
			}
			return result;
		}

		public static Condition[] toArray() {
			return new Condition[]{NEW, ALMOST_NEW, SLIGHT_TRACE, OBVIOUS_TRACE};
		}

		@Override
		public String toString() {
			String result = null;
			switch (this) {
				case NEW -> result = "全新";
				case ALMOST_NEW -> result = "几乎全新";
				case SLIGHT_TRACE -> result = "轻微使用痕迹";
				case OBVIOUS_TRACE -> result = "明显使用痕迹";
			}
			return result;
		}
	}
}
